package com.grantheath.erebus.view.transitionHandelers 
{
	import flash.display.DisplayObject;
	import flash.events.EventDispatcher;

	import gs.TweenLite;

	import com.grantheath.erebus.view.interfaces.IErebusPage;
	import com.grantheath.erebus.view.interfaces.IErebusTransitionHandeler;
	import com.grantheath.erebus.view.helpers.ErebusPageEvent;

	/**
	 * @author grantheath
	 */
	public class ErebusFadeTransitionHandeler extends EventDispatcher implements IErebusTransitionHandeler 
	{
		private var _page : IErebusPage;
		private var _duration : Number;
		private var _outDuration : Number;

		public function ErebusFadeTransitionHandeler(pageNode : IErebusPage) : void
		{
			_page = pageNode;
			_duration = 1;
			_outDuration = 1;
		}

		public function transitionIn() : void
		{
			DisplayObject(page).alpha = 0;
			page.pageLayer.addChild(DisplayObject(page));
			TweenLite.to(page, duration, {alpha : 1, onComplete : onTransitionIn});
		}

		public function transitionOut() : void
		{
			TweenLite.to(page, outDuration, {alpha : 0, onComplete : onTransitionOut});
		}

		public function get page() : IErebusPage
		{
			return _page;
		}

		//EVENT HANDELERS
		private function onTransitionIn() : void
		{
			dispatchEvent(new ErebusPageEvent(ErebusPageEvent.PAGE_TRANSITION_IN_COMPLETE));
		}

		private function onTransitionOut() : void
		{
			dispatchEvent(new ErebusPageEvent(ErebusPageEvent.PAGE_TRANSITION_OUT_COMPLETE));
		}

		//GETTERS AND SETTERS
		public function get duration() : Number
		{
			return _duration;
		}

		public function set duration(duration : Number) : void
		{
			_duration = duration;
		}

		public function get outDuration() : Number
		{
			return _outDuration;
		}

		public function set outDuration(outDuration : Number) : void
		{
			_outDuration = outDuration;
		}
	}
}
